def iter_func(X, a,c,m):
    Xi = X

    if m == 0 :
        yield X

    for i in xrange(1,m):
        yield Xi
        Xi = (a*Xi+c) % m

def main():
    D_INPUT = True

    if D_INPUT:
        X0,a,c,m = input()
        Y = input()
    else:
        X0,a,c = 0,16087,2
        m = 2147483647
        Y = 10

    f = iter_func(X0, a, c, m)

    i = 0
    req = set()
    for Yf in f:

        #print Yf,
        if Yf == Y:
            print "YES",
            break

        if not Yf in req :
            req.add(Yf)
        else :
            print "NO"
            break
    else:
        print "NO"

        #print f.next()


main()
